//
//  UIPopoverListView+Create.m
//  MovingLoaniOS
//
//  Created by RAIN on 2019/2/28.
//  Copyright © 2019 GWMFC. All rights reserved.
//

#import "UIPopoverListView+Create.h"
#import "Macros.h"
@implementation UIPopoverListView (Create)

#pragma mark Factory Initializer
+ (UIPopoverListView *)popListViewIn:(PopInView)viewController {
    UIPopoverListView *popListView = [[UIPopoverListView alloc] initWithFrame:[[self class] popViewFrame]];
    popListView.datasource = viewController;
    popListView.delegate = viewController;
    popListView.listView.scrollEnabled = YES;
    return popListView;
}

+ (UIPopoverListView *)popListViewWithTitle:(NSString *)title
                                 titleColor:(UIColor *)titleColor
                                     source:(NSArray *)source
                           inViewController:(PopInView)viewController
{
    UIPopoverListView *popListView = [[self class] popListViewIn:viewController];
    popListView.title = title;
    popListView.titleColor = titleColor;
    [popListView adjustHeightWithItems:source
                            unitHeight:90.0
                           limitHeight:CGRectGetHeight([[self class] popViewFrame])];
    return popListView;
}

+ (UIPopoverListView *)popListViewWithCell:(UINib *)cellNib
                 cellIdentifier:(NSString *)identifier
                          title:(NSString *)title
                     titleColor:(UIColor *)titleColor
                         source:(NSArray *)source
               inViewController:(PopInView)viewController
{
    UIPopoverListView *popListView = [[self class] popListViewWithTitle:title
                                                             titleColor:titleColor
                                                                 source:source
                                                       inViewController:viewController];
    [popListView.listView registerNib:cellNib forCellReuseIdentifier:identifier];
    return popListView;
}


#pragma mark - Public
+ (void)showPopListViewWithTitle:(NSString *)title
                          source:(NSArray *)source
                inViewController:(PopInView)viewController
{
    [[self class] showPopListViewWithTitle:title
                                titleColor:HEXCOLOR(0x304C9C)
                                    source:source
                          inViewController:viewController];
}

+ (void)showPopListViewWithCell:(UINib *)cellNib
                 cellIdentifier:(NSString *)identifier
                          title:(NSString *)title
                         source:(NSArray *)source
               inViewController:(PopInView)viewController
{
    [[self class] showPopListViewWithCell:cellNib
                           cellIdentifier:identifier
                                    title:title
                               titleColor:HEXCOLOR(0xCCAC69)
                                   source:source
                         inViewController:viewController];
}

+ (void)showPopListViewWithCell:(UINib *)cellNib
                 cellIdentifier:(NSString *)identifier
                          title:(NSString *)title
                     titleColor:(UIColor *)titleColor
                         source:(NSArray *)source
               inViewController:(PopInView)viewController
{
    [((UIViewController *)viewController).view endEditing:YES];
    UIPopoverListView *popListView = [[self class] popListViewWithCell:cellNib
                                                        cellIdentifier:identifier
                                                                 title:title
                                                            titleColor:titleColor
                                                                source:source
                                                      inViewController:viewController];
    [popListView show];
}


#pragma mark - Private
+ (void)showPopListViewWithTitle:(NSString *)title
                      titleColor:(UIColor *)titleColor
                          source:(NSArray *)source
                inViewController:(PopInView)viewController
{
    [((UIViewController *)viewController).view endEditing:YES];
    UIPopoverListView *popListView = [[self class] popListViewWithTitle:title
                                                             titleColor:titleColor
                                                                 source:source
                                                       inViewController:viewController];
    [popListView show];
}

+ (CGRect)popViewFrame {
    return CGRectMake(16.0, 100.0, Main_Screen_Width - 32.0, Main_Screen_Height - 200.0);;
}

@end
